<?
$ClientID = $_GET['ClientID'];
$query = " 	SELECT  site_visited_id,visit_date,visit_id, er_site.site_id, er_site.site_name
			FROM er_visit, er_site WHERE client_id=$ClientID
			AND er_site.site_id=er_visit.site_visited_id ORDER BY visit_date, visit_id";
		


$sql = r_db($query);



$result = mysql_num_rows($sql);



if($result > 0)

{
	
	//print "<form action=\"viewallclientvisit.php\" method=\"POST\" name=\"\" id=\"\">\n";
	
	
	
	print "<h1>Client Visits</h1>";
	echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n";
	
	print "<tr><th>Site Visited</th>";
	print "<th>Date</th>";
	print "<th>Action</th></tr>\n";
	
	$i = 0;
	
	for( $i; $i < $row = mysql_fetch_array($sql); $i++)
	
	{
		
		print "<tr>\n";
		
		print "<form action=\"?page=submit_visit_modify\" method=\"POST\" name=\"\" id=\"\">\n";
		
		print "<TD style=\"border: 1px solid black\">" . $row[4] . "</TD>\n";
		
		
		
		$DOB =  $row[1];
		
		//$DOB = date("Y-m-d",$DOB); //format the date in yyyy-mm-dd format eg 2000/09/08
		
		
		
		$DbDOB=explode("-",$DOB);
		
		$dayDOB=$DbDOB[2];
		
		$monthDOB=$DbDOB[1];
		
		$yearDOB=$DbDOB[0];
		
		$DOB=$dayDOB."/".$monthDOB."/".$yearDOB;
		
		
		
		print "<TD style=\"border: 1px solid black\">" . $DOB . "</TD>\n";
		
		print "<td style=\"border: 1px solid black\"><a href=\"?page=visit_modify&ClientID=$ClientID&VisitID=".$row['visit_id']."\"><img border=\"0\" src=\"images/Edit.gif\"></a>";
		
		print "<a href=\"?page=visit_modify&Delete=yes&ClientID=$ClientID&VisitID=".$row['visit_id']."\" onclick=\"if(!confirm('Are you sure to DELETE?')) return false\"><img border=\"0\" src=\"images/Delete.gif\"></a></td>";
				
		print "</form>\n";
		
		print "</tr>\n\n";
		
	}
	
	print "</table>\n";
	
	print "<input type=\"hidden\" name=\"totalRecords\" value=\"". $i . "\">";
	
	
	
	//print "</form>\n";
	
}

else

{
	
	echo "There are no visits recorded against currently client.";
	
}